package com.wms.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wms.entity.WProduct;
import com.wms.vo.WProductInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品信息表(WProduct)表数据库访问层
 *
 * @author Li Xiaoyu
 * @since 2023-10-21 21:12:55
 */
@Mapper
public interface WProductDao extends BaseMapper<WProduct> {
    @Select("select a.product_id,a.product_name,b.category_name,c.unit_name,a.price,a.num,a.max_num,a.min_num,d.factory_name,a.creator,a.mender,a.create_time,a.update_time,a.note " +
            "from w_product a,w_product_category b,w_product_unit c,w_factory d where a.product_type=b.id and a.product_unit=c.id and a.fid=d.factory_id")
    List<WProductInfo> selectProductInfo();

    @Update("update w_product set product_name=#{productName},product_type=(select id from w_product_category where category_name=#{categoryName}), " +
            "            product_unit=(select id from w_product_unit where unit_name=#{unitName}),price=#{price},num=#{num},max_num=#{maxNum},min_num=#{minNum}," +
            "            fid=(select factory_id from w_factory where factory_name=#{factoryName})," +
            "            creator=#{creator},mender=#{mender},create_time=#{createTime},update_time=#{updateTime},note=#{note} where product_id=#{productId}")
    int updateProductInfo(WProductInfo wProductInfo);

}

